//
//  HETWProtocalCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/18.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HETWProtocalCell.h"

@interface HETWProtocalCell ()

@property (nonatomic, strong) YYLabel *titleLb;

@end

@implementation HETWProtocalCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self initUI];
    }
    return self;
}

- (void)initUI {

    // 协议
    _titleLb = [YYLabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYFont(16);
    _titleLb.textColor = CNavDargGrayColor;
    _titleLb.numberOfLines = 0;
    [self.contentView addSubview:_titleLb];
 
    NSDictionary *attributes = @{NSFontAttributeName: DYFont(16), NSForegroundColorAttributeName: [UIColor blackColor]};

    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"  点击立即咨询代表同意《图文问诊协议》" attributes:attributes];
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:@"《图文问诊协议》"] color:CNavBgColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [self protocol];
    }];
    
    // 居中
    NSMutableParagraphStyle *timeParagraphStyle = [[NSMutableParagraphStyle alloc] init];
    timeParagraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:timeParagraphStyle range:NSMakeRange(0, text.length)];
 
//    notesPLb.preferredMaxLayoutWidth = KScreenWidth - 120;
    _titleLb.attributedText = text;
    
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
}

- (void)protocol {
    NSURL * file = [NSURL URLWithString: @"https://www.honglutec.com/platform-rules/tw_ask_rule.html"];
    RootWebViewController *webView = [[RootWebViewController alloc] initWithUrl:file.absoluteString];
    webView.isShowCloseBtn = YES;
    webView.showPageTitle = YES;
    RootNavigationController *nav = [[RootNavigationController alloc] initWithRootViewController:webView];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.proxyVC presentViewController:nav animated:YES completion:nil];
}

@end
